#!/bin/sh
cd `dirname $0`
printenv >env.properties
echo $$
echo $$><%appstart%>.pid

status=2
init=`dirname <%appstart%>`/init.sh
if [ -e "${init}" ]
then
    echo Found init.sh
    status_file=`dirname <%appstart%>`/../etc/status
    echo status_file:${status_file}
    start_time=`date "+%s"`
    while true
    do
        status=`cat ${status_file} | grep -Po "^\s*status\s*=\s*\d\s*$" | grep -Po "\d"`
        echo status:${status}
        if [ "${status}" == "2" ] ; then echo init completed!; break; fi
        if [ "${status}" == "1" ]
        then
            now_time=`date "+%s"`
            let elapse=now_time-start_time
            if [ ${elapse} -gt <%warmUp%> ] ;then  echo init time out!; break; fi
            echo wait init...
            sleep 10
        else
            if [ "${status}" == "" ] ;then echo status=1 >${status_file};fi
            chmod +x ${init}
            echo call init begin ...
            cd <%binPath%>
            ${init} 1><%binPath%>/../debug/init.out 2><%binPath%>/../debug/init.err
            echo call init end ...
        fi
    done
fi

if [ "${status}" == "2" ]
then
    chmod +x <%appstart%>
    cd <%binPath%>
    <%appstart%>
fi
cd `dirname $0`
rm -f <%appstart%>.pid


